import sys
import array;

def CountCommonSequence(s1, s2):
    size1 = len(s1)
    size2 = len(s2)
    css = [x[:] for x in [[0]*size2]*size1]
    for i in range(1,size1):
        for j in range(1,size2):
            css[i][j] = 0
    k = 0
    for i in range(0,size1):
        if(s1[i] == s2[0]):
            k = k + 1
        css[i][0] = k
    k = 0
    for j in range(0,size2):
        if(s1[0] == s2[j]):
            k = k + 1
        css[0][j] = k
    i = 1;
    j = 1;
    while i < size1 and j < size2:
        for x in range(i,size1):
            css[x][j] = css[x-1][j] + css[x][j-1] - css[x-1][j-1]
            if(s1[x] == s2[j]): css[x][j]  = css[x][j]  + css[x-1][j-1] + 1
        for y in range(j,size2):
            css[i][y] = css[i-1][y] + css[i][y-1] - css[i-1][y-1]
            if(s1[i] == s2[y]): css[i][y] = css[i][y] + css[i-1][y-1] + 1
        i = i + 1
        j = j + 1
        '''
    print("===========")
    for i in range(0,size1):
        print(css[i])
        pass;
        '''
    ret =  css[size1-1][size2-1]
    if(size1 - 1 > 0):
        ret = ret - css[size1-2][size2-1]
    return ret

def CountSquares(strin):
    count = 0
    if len(strin) <= 1:
        return 0
    for i in range(1,len(strin)):
        strl = strin[0 : i]
        strr = strin[i:]
        more =  CountCommonSequence(strl, strr);
        count = count + more;
        #print("%s : %s + %s" % (strl,strr,more))
    return count



data = sys.stdin.readlines()

#CountCommonSequence("jmowf", "rxsjybldbef");
lines = int(data[0])
count = 0;
for strin in data[1:]:
    print(CountSquares(strin) % 1000000007)
    count = count + 1
    if(count == lines): break;
    
    #print(strin + " has " +str(CountSquares(strin)) + " squares")
